﻿using RuoVea.ExDto;
using RuoVea.ExEnum;
using RuoVea.OmiApi.Article.Entitys;
using SqlSugar;
using System.ComponentModel.DataAnnotations;

namespace RuoVea.OmiApi.Article.Service.Dto;

/// <summary>
/// 分类
/// </summary>
public class CategoryParam : PageParam
{
    /// <summary>
    /// 父分类ID，0表示一级分类
    /// </summary>
    public long? PId { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 分类别名(URL友好格式)
    /// </summary>
    public string Code { get; set; }

    /// <summary>
    /// 状态-正常_0、停用_1 
    /// </summary>
    public YesOrNot? IsDisable { get; set; }

    /// <summary>
    /// 
    /// </summary>
    private int _currentPage;
    /// <summary>
    /// 
    /// </summary>
    public int CurrentPage
    {
        get { return _currentPage; }
        set
        {
            _currentPage = value;
            base.PageNo = value;
        }
    }
}


/// <summary>
/// 分类
/// </summary>
public class CategoryQuery
{
    /// <summary>
    /// 
    /// </summary>
    public long? UserId { get; set; }
    /// <summary>
    /// 父分类ID，0表示一级分类
    /// </summary>
    public long? PId { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 分类别名(URL友好格式)
    /// </summary>
    public string Code { get; set; }

    /// <summary>
    /// 状态-正常_0、停用_1 
    /// </summary>
    public YesOrNot? IsDisable { get; set; }

    /// <summary>
    /// 父分类ID，0表示一级分类
    /// </summary>
    public YesOrNot? IsRoot { get; set; }
}

/// <summary>
/// 分类
/// </summary>
public class CategoryInputDto
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public long Id { get; set; }
    /// <summary>
    /// 父分类ID，0表示一级分类
    /// </summary>
    public long? PId { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    [Required, MaxLength(64)]
    public string Name { get; set; }

    /// <summary>
    /// 分类别名(URL友好格式)
    /// </summary>
    [Required, MaxLength(200)]
    public string Code { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get; set; } = 10;

    /// <summary>
    /// 备注
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    /// 状态-正常_0、停用_1 
    /// </summary>
    public YesOrNot? IsDisable { get; set; } = YesOrNot.N;
}

/// <summary>
/// 分类
/// </summary>
public class CategoryDto  
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public long Id { get; set; }
    /// <summary>
    /// 父分类ID，0表示一级分类
    /// </summary>
    public long? PId { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    [Required, MaxLength(64)]
    public string Name { get; set; }

    /// <summary>
    /// 分类别名(URL友好格式)
    /// </summary>
    [Required, MaxLength(200)]
    public string Code { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int? Sort { get; set; } = 10;

    /// <summary>
    /// 备注
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    /// 状态-正常_0、停用_1 
    /// </summary>
    public YesOrNot? IsDisable { get; set; } = YesOrNot.N;

    /// <summary>
    /// 导航属性 - 子分类列表（一对多关系）
    /// </summary>
    public List<ArtCategory>? Children { get; set; }
}

/// <summary>
/// 构造的树
/// </summary>
public class CategoryOutput
{
    /// <summary>
    /// Id
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 父Id
    /// </summary>
    public long Pid { get; set; }

    /// <summary>
    /// 编码
    /// </summary>
    public string Code { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 子节点集合
    /// </summary>
    public List<CategoryOutput> Children { get; set; } = new List<CategoryOutput>();
}

/// <summary>
/// 树形结构DTO
/// </summary>
public class CategoryTreeDto : CategoryDto
{
    /// <summary>
    /// 子节点列表
    /// </summary>
    public new List<CategoryTreeDto> Children { get; set; } = new List<CategoryTreeDto>();

    /// <summary>
    /// 是否有子节点
    /// </summary>
    public bool HasChildren => Children != null && Children.Any();

    /// <summary>
    /// 层级深度（可选）
    /// </summary>
    public int Level { get; set; }
}